package util

import (
	"github.com/cilidm/toolbox/OS"
	"os"
	"path/filepath"
	"strings"
)

func Find(what int, where []int) (idx int) {
	for i, v := range where {
		if v == what {
			return i
		}
	}
	return -1
}

/**
 * 判断文件是否存在  存在返回 true 不存在返回false
 */
func CheckFileIsExist(filename string) bool {
	var exist = true
	if _, err := os.Stat(filename); os.IsNotExist(err) {
		exist = false
	}
	return exist
}

/**
 * 判断路径是否包含过滤路径
 */
func HasPathPrefix(export []string, p string) bool {
	for _, v := range export {
		if strings.HasPrefix(p, v) {
			return true
		}
	}
	return false
}

func FilePathJoinChange(p string) (np string) {
	if OS.IsWindows() {
		np = strings.ReplaceAll(filepath.Join(p, "*"), "\\", "/")
	} else {
		np = filepath.Join(p, "*")
	}
	return
}
